/**
 * @file    instructions.h
 * @author  Thomas Di'Meco and Matthieu Maugard
 * @brief   Instructions defines and utilities
 */

#ifndef INSTRUCTIONS_H_
#define INSTRUCTIONS_H_

#define INSTRUCTION_NUMBER 11


/**
 * Instructions enum. This enumerate all available instructions
 */
enum
{
    LOAD,  // Load
    STORE, // Store
    ADD,   // Add
    SUB,   // Sub
    JMP,   // Jump
    JEQ,   // Jump if equal
    CALL,  // Call
    RET,   // Return
    PUSH,  // Push
    POP,   // Pop
    HALT   // Halt
};

/**
 * Instructions strings. String equivalent for each instruction in
 * the instructions enum (that must be in the same order)
 */
extern const char * instruction_str[INSTRUCTION_NUMBER];

/**
 * Mode enum. This enumerate all available addressing modes
 */
enum
{
    REGREG = 0,  // 1 word
    REGIMM = 4,  // 2 words
    REGDIR = 8,  // 2 words
    REGIND = 12, // 1 word
    DIRIMM = 5,  // 3 words
    DIRREG = 1,  // 2 words
    INDIMM = 6,  // 2 words
    INDREG = 2,  // 1 word
    UNKUNK = 0xffff // unknown mode
};

/**
 * Individual mode enum. This enumerate addressing modes for an operand
 */
enum
{
    UNK, // Unknown
    REG, // Register
    IMM, // Immediate
    DIR, // Direct
    IND  // Indirect
};

/**
 * Returns the instruction equivalent to the given string
 * @param str The instruction string to parse
 * @return The instruction equivalent (see instructions enum)
 *         or -1 if the instruction does not exist
 */
int16_t get_instruction (char * str);

#endif /* INSTRUCTIONS_H_ */
